<?php
/**
 * 上分行按钮工具类
 */
namespace App\Admin\Extensions;

use Encore\Admin\Admin;

class ScoreHandle
{

    protected function script()
    {
        $prefix = config('admin.route.prefix');
        return <<<EOT
        $('.grid-check-user-migration').on('click', function () {
            var course_id = $(this).data('course_id');
            var total = $(this).data('total');
            var student_id = $(this).data('student_id');
            $.ajax({
                method: 'get',
                url: '/$prefix/tm/insertstudent',
                data: {
                    _method:'get',
                    _token:LA.token,
                    course_id:course_id,
                    student_id:student_id,
                    total:total,
                },
                success: function (data) {
                    if(data.code == 1){
                        $("#view_member_detail2").empty();
                        $("#view_member_detail2").html(data.msg);
                    }
                }
            });
        });
       
         $('#usermigration').on('click', function () {
         
            var exam_type = $('#exam_type').val();
            var degree = $('#degree').val();
            var course_id = $('#course_id').val();
            var student_id = $('#student_id').val();
            if(!exam_type) {
                alert('考试类型不为空');
                return;
            }
           if(!degree) {
                alert('分数不为空');
                return;
            }
            $.ajax({
                method: 'get',
                url: '/$prefix/tm/insertstudentsuccesss',
                data: {
                    _method:'get',
                    _token:LA.token, 
                    exam_type:exam_type,
                    degree:degree,
                    course_id:course_id,
                    student_id:student_id,
                },
                success: function (data) {
                    if(data.code == 0) {
                         alert(data.msg)
                          location.reload();  
                    }else {
                        alert(data.msg)
                    }
                }
            });
        });
EOT;
    }

    protected function render()
    {
        Admin::script($this->script());

        $str = "<div class=\"modal fade\" id=\"myModal3\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"myModalLabel\">
  <div class=\"modal-dialog modal-lg\" role=\"document\" style='width: 600px;'>
    <div class=\"modal-content\">
      <div class=\"modal-header\">
        <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Close\"><span aria-hidden=\"true\">&times;</span></button>
        <h4 class=\"modal-title\" >成绩录入</h4>
      </div>
      
        <div class=\"modal-body\">
            <form id=\"view_member_detail2\" style='font-size: 18px' ></form>
        </div>
      <div class=\"modal-footer\">
        
        <button type=\"button\" class=\"btn btn-primary\"  id='usermigration'>确定</button>
      </div>
    </div>
  </div>
</div>";
        return $str;
    }

    public function __toString()
    {
        return $this->render();
    }
}